<?php
/**
 * 没有任何逻辑的Model类
 * @author xiao
 */
namespace App\Models\Express;
use Larfree\Models\Api;
use App\Scopes\Express\ExpressAttendScope;
class ExpressAttend extends Api
{
    use ExpressAttendScope;

    public  function attendClass($courseId,$userId){
        $check= $this->query()->where('course_id',$courseId)->where('user_id',$userId)->first();
        if($check){
            return true;
        }else{
            $data=[
                'course_id'=>$courseId,
                'user_id'=>$userId
            ];
            $this->create($data);
            $course=ExpressCourse::query()->where('id',$courseId)->first();
            $course->increment('user_count',1);
            $course->save();
        }
    }
}
